import React, { useEffect, useState } from "react";

export default function App() {
  let [opacity, setOpacity] = useState(1)

  //初始化的时候添加一个定时器
  useEffect(() => {
    const opacityTimer = setInterval(() => {
      opacity -= 0.05;
      if (opacity <= 0) {
        opacity = 1
      }
      setOpacity(opacity)
    }, 100)


    return ()=>{
      clearInterval(opacityTimer)
      // 清除定时器  clear 清除的意思
    }
  }, [])



  return (
    <div>
      <h1 style={{ opacity }}>ReactHook真好用</h1>
    </div>
  )

}
 
// opacity  不透明度